package main

import (
	"ginEssential/controller"
	"ginEssential/middleware"
	"github.com/gin-gonic/gin"
)

func CollectRouter(r *gin.Engine) *gin.Engine {
	r.Use(middleware.CORSMiddleware(),middleware.RecoverMiddleware())
	r.POST("/api/auth/register", controller.Register)
	r.POST("/api/auth/login", controller.Login)
	r.GET("/api/auth/info", middleware.AuthMiddleware(), controller.Info)
	categoryRoutes:=r.Group("/categories")
	catergoryController:=controller.NewCategoryController()
	categoryRoutes.POST("",catergoryController.Create)
	categoryRoutes.PUT("/:id",catergoryController.Update)
	categoryRoutes.GET("/:id",catergoryController.Show)
	categoryRoutes.DELETE("/:id",catergoryController.Delete)
	//PATCH 和put方法类似，只不过put是全部替换，而PATCH是修改部分
	//categoryRoutes.PATCH("/:id")

	postRoutes:=r.Group("/posts")
	postRoutes.Use(middleware.AuthMiddleware())
	postController:=controller.NewPostController()
	postRoutes.POST("",postController.Create)
	postRoutes.PUT("/:id",postController.Update)
	postRoutes.GET("/:id",postController.Show)
	postRoutes.DELETE("/:id",postController.Delete)
	postRoutes.POST("/page/list",postController.PageList)
	return r
}
